﻿using Coldairarrow.Business.PB;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.PB;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.PB
{
    [Route("/PB/[controller]/[action]")]
    public class PB_ProductionOrderDetailController : BaseApiController
    {
        #region DI

        public PB_ProductionOrderDetailController(IPB_ProductionOrderDetailBusiness pB_ProductionOrderDetailBus)
        {
            _pB_ProductionOrderDetailBus = pB_ProductionOrderDetailBus;
        }

        IPB_ProductionOrderDetailBusiness _pB_ProductionOrderDetailBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<PB_ProductionOrderDetail>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _pB_ProductionOrderDetailBus.GetDataListAsync(input);
        }

        /// <summary>
        /// 联合查询生产订单信息,所有ID获取对应名称
        /// </summary>
        /// <param name="input">条件信息</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<PB_ProductionOrderDetailListDTO>> GetDataListShowAllName(PB_ProductionOrderDetailInput input)
        {
            return await _pB_ProductionOrderDetailBus.GetDataListShowAllNameAsync(input);
        }

        /// <summary>
        /// 通过项目id获取任务单信息
        /// </summary>
        /// <param name="ProjectId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<ProjectProductionOrderList>> GetProjectProductionOrderList(PageInput<ProSubvConditionDTO> input, string ProjectId) {
            var res = _pB_ProductionOrderDetailBus.GetProjectProductionOrderList(input,ProjectId);
            return  await res;
        }

        [HttpPost]
        public async Task<PB_ProductionOrderDetail> GetTheData(IdInputDTO input)
        {
            return await _pB_ProductionOrderDetailBus.GetTheDataAsync(input.id);
        }

        [HttpPost]
        public async Task AddDataAsyncs(List<PB_ProductionOrderDetail> data)
        {
            await _pB_ProductionOrderDetailBus.AddDataAsyncs(data);
        }

        /// <summary>
        /// 扫码获取任务单明细信息
        /// </summary>
        /// <param name="OrderDetailQrCode"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PB_ProductionOrderDetailData> GetTheDataOrderDetail(string OrderDetailQrCode)
        {
            return await _pB_ProductionOrderDetailBus.GetTheDataOrderDetail(OrderDetailQrCode);
        }

        /// <summary>
        /// 扫码获取任务单明细信息(输入)
        /// </summary>
        /// <param name="OrderDetailQrCode"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PB_ProductionOrderDetailData> GetTheDataOrderDetailInput(string OrderDetailQrCode)
        {
            return await _pB_ProductionOrderDetailBus.GetTheDataOrderDetailInput(OrderDetailQrCode);
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(PB_ProductionOrderDetail data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _pB_ProductionOrderDetailBus.AddDataAsync(data);
            }
            else
            {
                await _pB_ProductionOrderDetailBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _pB_ProductionOrderDetailBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}